#include "UIMessageChatModel.h"
#include <QDateTime>
#include <QDebug>
#include "IM_CoreApi.h"
using namespace IM_GUI_KIT;
/**
 * @brief UIMessageChatModel::UIMessageChatModel
 * @param parent
 * 属性
 * userChat_Icon_img_src
 * chat_name
 * DataBody
 * mySend
 */
UIMessageChatModel::UIMessageChatModel(QObject *parent):QObject (parent)
{
 qDebug()<<"init UIMessageChatModel" ;
}

UIMessageChatModel::~UIMessageChatModel()
{
     qDebug()<<"delete UIMessageChatModel";
}

QString UIMessageChatModel::getSession() const
{
  return m_sessionId;
}

void UIMessageChatModel::setSession(const QString &sessionid)
{
  if(sessionid!=m_sessionId)
      m_sessionId=sessionid;
  emit sessionChanged();
}

UIMessageChatModel::UIMessageChatModel(const QString sessionid  , const QString &name, const QString &icon, const int64_t timestamp, const QString msgBody, int unRead, QObject *parent):QObject (parent)
{
  m_sessionId=sessionid;
  m_name=name;
  m_icon=icon;
  m_timestamp=timestamp;
  m_mysend=IM_CoreApi::Instance()->getMyUid()!=sessionid;
  m_time=QDateTime::fromTime_t(timestamp/1000).toString("yyyy-MM-dd hh:mm:ss");
  m_unread=unRead;
}

QString UIMessageChatModel::getName() const
{
    return m_name;
}

void UIMessageChatModel::setName(const QString &name)
{
    if(name!=m_name)
        m_name=name;
    emit nameChanged();
}

QString UIMessageChatModel::getBody() const
{
    return m_body;
}

void UIMessageChatModel::setBody(const QString &body)
{
    if(body!=m_body)
        m_body=body;
    emit bodyChanged();
}


QString UIMessageChatModel::getIcon() const
{
    return m_icon;
}

void UIMessageChatModel::setIcon(const QString &icon)
{
    if (m_icon==icon)
        m_icon=icon;
    emit iconChanged();
}

QString UIMessageChatModel::getTime() const
{
    return m_time;

}

void UIMessageChatModel::setTime(const QString &time)
{

    if (m_time==time)
        m_time=time;
    emit timeChanged();
}



int UIMessageChatModel::getUnread()
{
    return m_unread;
}

void UIMessageChatModel::setUnread(const int &unread)
{
    if (m_unread==unread)
        m_unread=unread;
    emit unreadChanged();
}

int UIMessageChatModel::getMySend()
{
  return m_mysend;
}

void UIMessageChatModel::setMySend(const bool mysend)
{
  m_mysend=mysend;
  emit mySendChanged();
}




void UIMessageChatModel::setTimeStamp(const int64_t time)
{
  if(time!=m_timestamp){
      m_timestamp=time;
      m_time=QDateTime::fromTime_t(time/1000).toString("yyyy-MM-dd hh:mm:ss");
      emit timeChanged();
    }
}

int64_t UIMessageChatModel::getTimeStamp()
{
  return m_timestamp;
}

void UIMessageChatModel::setID(const QString &id)
{
  this->m_id=id;
}

QString UIMessageChatModel::getID() const
{
  return m_id;
}

QString UIMessageChatModel::getMessageID() const
{
  return m_msgid;
}

